//
//  RBGoodsDetailVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/23.
//

#import "RBGoodsDetailVC.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RanTool.h"
#import "RBPager.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "UIViewController+RBAdd.h"
#import "RBMediaPlayerView.h"
#import "RBGoodsDetailBannerView.h"
#import "RBNavigationBar.h"
#import "UIButton+RBAdd.h"
#import "RBCollectionReusableView.h"
#import "RBGradientView.h"
#import "RBGoodsDetailAppraiseCell.h"
#import "UIScrollView+RBAddHorizontal.h"
#import "RBGoodsDetailParamPopVC.h"
#import "RBGoodsDetailWebView.h"
#import "RBConfirmOrderVC.h"
#import "RBGoodsDetailAttachPopVC.h"
#import "RBGoodsSharePopVC.h"
#import "UIViewController+RBAdd.h"
#import "RBGoodsDetailResponse.h"
#import "RBGoodsAddToothPopVC.h"
#import "RBGoodsDetailMultipleChoosePopVC.h"
#import "RBPickerVC.h"
#import "RBAddCartResponse.h"
#import <NSArray+YYAdd.h>
#import "RBUploadTool.h"
#import "RBShopDetailVC.h"
#import "RBShopIntroVC.h"
#import "RBGoodsEvaluateListVC.h"

@interface RBGoodsDetailVC ()
<UICollectionViewDataSource, UICollectionViewDelegate,
UICollectionViewDelegateFlowLayout>
//导航栏
@property (nonatomic, strong) RBNavigationBar *navigationBar;
@property (nonatomic, strong) UIView *backBtn;
@property (nonatomic, strong) UILabel *titleL;
//collectionView
@property (nonatomic, strong) UICollectionView *collectionView;
//底部view
@property (nonatomic, strong) UIView *bottomView;
//webView
@property (nonatomic, strong) UIView *goodsDetailView;
@property (nonatomic, strong) RBGoodsDetailWebView *detailWebView;
@property (nonatomic, strong) RBGroupModel *detailWebGroup;
//数据源
@property (nonatomic, retain) NSMutableArray *dataSource;
@property (nonatomic, retain) NSArray *specArray;

@property (nonatomic, strong) RBGoodsDetailResponse *response;

@property (nonatomic, strong) NSMutableArray *toothBtnsArrayM;

@property(nonatomic, copy) NSString *pname;
@property(nonatomic, copy) NSString *pgender;
@property(nonatomic, copy) NSString *dnote;
@property(nonatomic, strong) NSArray *pics;

@property (nonatomic, strong) RBUploadTool *uploadTool;
/** 0 添加购物车 1立即购买 */
@property (nonatomic, assign) NSInteger actionType;

@end

@implementation RBGoodsDetailVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self getData];
}

#pragma mark - Private

- (void)setup {
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = [RBThemeConfig bgGrayColor];
    self.collectionView.hidden = NO;
    self.navigationBar.hidden = NO;
    self.bottomView.hidden = YES;
}

- (void)fillData {
    //model
    RBGoodsDetailModel *detailModel = self.response.data;
    //底部view
    [self reloadCollect];
    [self reloadPrice];
    self.bottomView.hidden = NO;
    //轮播图
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerView = ({
            RBGoodsDetailBannerView *view = RBGoodsDetailBannerView.new;
            view.videoFirst = detailModel.picurl;
            view.dataSource = ({
                NSMutableArray *arrayM = NSMutableArray.array;
                if (detailModel.video && detailModel.video.length > 0) {
                    [arrayM addObject:[NSString stringWithFormat:@"%@/%@", _Domain, detailModel.video]];
                }
                
                if (detailModel.picarr && [detailModel.picarr count] > 0) {
                    [arrayM addObjectsFromArray:detailModel.picarr];
                } else {
                    [arrayM addObject:detailModel.picurl];
                }
                
                arrayM;
            });
            view;
        });
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, kRBMainScreenWidth);
        group;
    })];
    //商品信息
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerView = [self infoViewWith:detailModel];
        group.headerView.tag = 10086;
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, group.headerView.esSize.height);
        group;
    })];
    //属性
    self.specArray = ({
        NSMutableArray *arrayM = NSMutableArray.array;
        for (RBGoodsDetailSpecModel *model in detailModel.goods_spec) {
            if (model.status == 1) {
                [arrayM addObject:model];
                model.level = 2;
                if (model.spec.count) {
                    RBGoodsDetailSpecItemModel *l2Model = model.spec.firstObject;
                    if (l2Model.spec_son.count) {
                        model.level = 3;
                    }
                }
                if(model.model_type == 1) {
                    for (RBGoodsDetailSpecItemModel *itemModel in model.spec) {
                        if (itemModel.is_default) {
                            model.selIndex = [model.spec indexOfObject:itemModel];
                            break;
                        }
                    }
                }
            }
        }
        arrayM;
    });
    //属性赋值
    for (RBGoodsDetailSpecModel *model in self.specArray) {
        [self.dataSource addObject:({
            RBGroupModel *group = RBGroupModel.new;
            group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
            switch (model.model_type) {
                case 1 : {
                    group.headerView = [self paramsSingleDisplayType1ViewWithData:model];
                }   break;
                case 2 : {
                    group.headerView = [self paramsMultiplePopType2ViewWithData:model];
                }   break;
                case 3 : {
                    group.headerView = [self paramsSelectorPopType3ViewWithData:model];
                }   break;
                case 4 : {
                    group.headerView = [self paramsSinglePopType4ViewWithData:model];
                }   break;
                case 5 : {
                    group.headerView = [self paramsChooseToothDisplayType5ViewWithData:model];
                }   break;
                case 6 : {
                    group.headerView = [self paramsAddToothPopType6ViewWithData:model];
                }   break;
            }
            group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, group.headerView.esSize.height);
            group;
        })];
    }
    //占位
    [self.dataSource addObject:[self paddingGroupWithHeight:Zoom(10)]];
    //评价
    if (detailModel.evaluate.count > 0) {
        [self.dataSource addObject:({
            RBGroupModel *group = RBGroupModel.new;
            group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
            group.headerView = ({
                UIView *view = UIView.new;
                [view view_addView:({
                    UIView *view = UIView.new;
                    view.backgroundColor = UIColor.whiteColor;
                    [view rbSetCorner:UIRectCornerTopLeft | UIRectCornerTopRight radius:Zoom(8)];
                    [view rbAddTapGesWithTarget:self action:@selector(checkTotalEvaluateAction)];
                    
                    [view h_view_addView:({
                        UILabel *view = [RanTool labelWithFontSize:Zoom(18) weight:2 color:[RBThemeConfig textBlackColor] align:0 text:@"评价"];
                        [view addPriority:1];
                        view;
                    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(14) right:0 centerY:0];
                    
                    [view h_view_addView:[RanTool labelWithFontSize:Zoom(15) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:[NSString stringWithFormat:@"(%@)", detailModel.evaluate_count]] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
                    
                    [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(11) centerY:YES];
                    
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
                view;
            });
            group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(50));
            group.footerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
            group.footerView = ({
                UIView *view = UIView.new;
                [view view_addView:({
                    UIView *view = UIView.new;
                    view.backgroundColor = UIColor.whiteColor;
                    [view rbSetCorner:UIRectCornerBottomLeft | UIRectCornerBottomRight radius:Zoom(8)];
                    [view view_addView:({
                        UILabel *view = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textBlackColor] align:1 text:@"查看全部" bgColor:UIColor.whiteColor radius:Zoom(15)];
                        [view rbSetBorderWitdh:1 borderColor:[UIColor colorWithHexString:@"#BFBFBF"]];
                        [view rbAddTapGesWithTarget:self action:@selector(checkTotalEvaluateAction)];
                        view;
                    }) withHeight:Zoom(30) width:Zoom(100) top:Zoom(14) bottom:CGFLOAT_MIN left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
                view;
            });
            group.footerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(59));
            group.cellModels = ({
                NSMutableArray *arrayM = NSMutableArray.array;
                for (RBGoodsDetailEvaluateModel *model in detailModel.evaluate) {
                    [arrayM addObject:({
                        RBCellModel *cellModel = RBCellModel.new;
                        cellModel.reuseCellIdentifier = NSStringFromClass(RBGoodsDetailAppraiseCell.class);
                        cellModel.cellData = model;
                        cellModel;
                    })];
                }
                arrayM;
            });
            group;
        })];
        
        //占位
        [self.dataSource addObject:[self paddingGroupWithHeight:Zoom(10)]];
    }
    //店铺信息
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
        group.headerView = ({
            UIView *view = UIView.new;
            [view view_addView:[self shopViewWith:detailModel] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
            view;
        });
        
        group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, group.headerView.esSize.height);
        group;
    })];
    //占位
    [self.dataSource addObject:[self paddingGroupWithHeight:Zoom(10)]];
    //为你推荐
    if (detailModel.cate_goods.count > 0) {
        [self.dataSource addObject:({
            RBGroupModel *group = RBGroupModel.new;
            group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
            group.headerView = ({
                UIView *view = UIView.new;
                [view view_addView:[self recViewWith:detailModel] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
                view;
            });
            group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, group.headerView.esSize.height);
            group;
        })];
        //占位
        [self.dataSource addObject:[self paddingGroupWithHeight:Zoom(10)]];
    }
    //详情
    if (detailModel.content.length > 0) {
        [self.dataSource addObject:({
            RBGroupModel *group = RBGroupModel.new;
            group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
            group.headerView = ({
                UIView *view = UIView.new;
                [view view_addView:[self detailView] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
                view;
            });
            group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, group.headerView.esSize.height);
            group;
        })];
        
        [self.dataSource addObject:({
            RBGroupModel *group = RBGroupModel.new;
            self.detailWebGroup = group;
            group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
            group.headerView = self.goodsDetailView;
            group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, 1);
            group.footerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
            group.footerView = ({
                UIView *view = UIView.new;
                [view view_addView:({
                    UIView *view = UIView.new;
                    view.backgroundColor = UIColor.whiteColor;
                    [view rbSetCorner:UIRectCornerBottomLeft | UIRectCornerBottomRight radius:Zoom(8)];
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
                view;
            });
            group.footerReferenceSize = CGSizeMake(kRBMainScreenWidth, Zoom(15));
            group;
        })];
        
        LCWeakSelf;
        self.detailWebView.heightChangeBlock = ^(CGFloat currentHeight) {
            weakSelf.detailWebGroup.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, currentHeight);
            NSInteger section = [weakSelf.dataSource indexOfObject:weakSelf.detailWebGroup];
            [weakSelf.collectionView reloadSections:[NSIndexSet indexSetWithIndex:section]];
        };
        self.detailWebView.content = detailModel.content;
        //占位
        [self.dataSource addObject:[self paddingGroupWithHeight:Zoom(13)]];
    }
    //刷新
    [self.collectionView reloadData];
}
//刷新价格
- (void)reloadPrice {
    //model
    RBGoodsDetailModel *model = self.response.data;
    //属性
    CGFloat total_price = [model.price floatValue];
    for (RBGoodsDetailSpecModel *model in self.specArray) {
        if (model.model_type == 6) {
            for (RBGoodsDetailSpecItemModel *item in model.spec) {
                if (item.selected) {
                    total_price = total_price + item.count * [item.spec_price floatValue];
                }
            }
        }
    }
    model.total_price = [NSString stringWithFormat:@"%.2f", total_price];
    //查view
    for (RBGroupModel *group in self.dataSource) {
        if (group.headerView.tag == 10086) {
            UILabel *label = [group.headerView viewWithTag:1008611];
            label.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(17)] color:[RBThemeConfig priceRedColor] string:@"¥"];
                NSArray *priceComponets = [RanTool priceFromPrice:model.total_price];
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(30)] color:[RBThemeConfig priceRedColor] string:priceComponets[0]];
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(24)] color:[RBThemeConfig priceRedColor] string:[NSString stringWithFormat:@".%@", priceComponets[1]]];
                [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[UIColor colorWithHexString:@"#8F8F8F"] string:@"　"];
                [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[UIColor colorWithHexString:@"#8F8F8F"] string:[NSString stringWithFormat:@"￥%@", model.shop_price] lineSpacing:0 througnLineHeight:1 throughLineColor:[UIColor colorWithHexString:@"#8F8F8F"]];
            }];
        }
    }
}
//刷新收藏
- (void)reloadCollect {
    UILabel *aL = [self.bottomView viewWithTag:1001012];
    UIImageView *imgV = [self.bottomView viewWithTag:1001011];
    
    if ([self.response.data.is_collect isEqualToString:@"1"]) {
        imgV.image = [UIImage imageNamed:@"orderDetailCollect"];
        aL.text = @"已收藏";
    } else {
        imgV.image = [UIImage imageNamed:@"orderDetailCollect"];
        aL.text = @"收藏";
    }
}

#pragma mark - Network
//详情请求
- (void)getData {
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"good_id"] = self.id;
    } path:@"api/good_info" post:YES log:YES responseClass:RBGoodsDetailResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(id data) {
        weak_self.response = data;
        [weak_self fillData];
    } failBlock:^(RBGoodsDetailResponse *data) {
        [weak_self.view showTip:data.message completion:nil];
    } reloadBlock:nil];
}
//收藏
- (void)collectTap {
    LCWeakSelf;
    [self.defaultHm requestWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"goodsid"] = self.id;
        dicM[@"type"] = @"1";
    } log:YES post:YES cancelLastRequest:NO fileParam:nil fileProgress:nil responseClass:RBResponse.class pathName:@"han_store_do_collect" completion:^(RBResponse *response) {
        if (response.succeed) {
            if ([self.response.data.is_collect isEqualToString:@"1"]) {
                self.response.data.is_collect = @"0";
            } else {
                self.response.data.is_collect = @"1";
            }
            
            [weakSelf reloadCollect];
            
            [JKToast showWithText:response.message];
        }
    }];
}
//上传患者的图片
- (void)uploadPatientPics {
    __weak typeof(self) weak_self = self;
    if (self.pics.count) {
        [self.uploadTool uploadData:({
            NSMutableArray *array = NSMutableArray.array;
            for (NSString *path in self.pics) {
                RBUploadModel *model = RBUploadModel.new;
                model.source = path;
                [array addObject:model];
            }
            array;
        }) withCompletion:^(NSArray *data) {
            [weak_self addCartRequestWithImgPath:data];
        }];
    } else {
        [self addCartRequestWithImgPath:@[]];
    }
}
//添加购物车
- (void)addCartRequestWithImgPath:(NSArray *)imgPath {
    NSString *specString = [self handleChooseSpec];
    LCWeakSelf;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"shop_id"] = self.response.data.shop_id;
        dicM[@"good_id"] = self.response.data.id;
        dicM[@"good_price"] = self.response.data.total_price;
        dicM[@"user_good_price"] = self.response.data.price;
        dicM[@"spec_key"] = specString;
        dicM[@"patient_name"] = self.pname;
        dicM[@"patient_sex"] = self.pgender;
        dicM[@"postscript"] = self.dnote;
        if (imgPath.count > 0) {
            dicM[@"picarr"] = [imgPath componentsJoinedByString:@","];
        }
    } path:@"api/add_cart" post:YES log:YES responseClass:RBAddCartResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(RBAddCartResponse *data) {
        if(weakSelf.actionType == 1) {
            RBConfirmOrderVC *vc = RBConfirmOrderVC.new;
            vc.type = RBConfirmOrderTypeFromGoodsDetail;
            vc.cartId = data.cart_id;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        } else {
            [weakSelf.view showTip:@"添加购物车成功" completion:nil];
        }
    } failBlock:^(RBAddCartResponse *data) {
        [weakSelf.view showTip:data.message completion:nil];
    } reloadBlock:^{
        
    }];
}

#pragma mark - Event
//返回
- (void)backBtnTapped {
    [self.navigationController popViewControllerAnimated:YES];
}
//分享
- (void)shareBtnTapped {
    RBGoodsSharePopVC *vc = RBGoodsSharePopVC.new;
    [self presentVc:vc];
}
//选择牙齿
- (void)toothBtnTapped: (UIButton *)btn {
    btn.selected = !btn.selected;
    RBGoodsDetailSpecItemModel *model = btn.rbExData;
    model.selected = btn.selected;
}
//查看全部评价
- (void)checkTotalEvaluateAction {
    RBGoodsEvaluateListVC *vc = RBGoodsEvaluateListVC.new;
    vc.goods_id = self.id;
    [self.navigationController pushViewController:vc animated:YES];
}
//联系客服
- (void)clickContactService {
    [UIApplication LC_openURL_phone:self.response.data.shop_info.mobile];
}
//店铺的商品
- (void)tapShopGood:(UITapGestureRecognizer *)ges {
    RBGoodsDetailShopGoodsModel *model = ges.view.rbExData;
    RBGoodsDetailVC *vc = RBGoodsDetailVC.new;
    vc.id = model.id;
    [self.navigationController pushViewController:vc animated:YES];
}
//进店逛逛
- (void)tapShop:(UITapGestureRecognizer *)ges {
    RBShopDetailVC *vc = RBShopDetailVC.new;
    vc.id = self.response.data.shop_info.id;
    [self.navigationController pushViewController:vc animated:YES];
}
//店铺信息
- (void)tapShopInfo:(UITapGestureRecognizer *)ges {
    RBShopIntroVC *vc = RBShopIntroVC.new;
    vc.id = self.response.data.shop_info.id;
    [self.navigationController pushViewController:vc animated:YES];
}

//加入购物车
- (void)addCartBtnTapped {
    self.actionType = 0;
    [self judgeSpecChoose];
}
//立即购买
- (void)buyBtnTapped {
    self.actionType = 1;
    [self judgeSpecChoose];
}
//判断
- (void)judgeSpecChoose {
    for (RBGoodsDetailSpecModel *model in self.specArray) {
        NSString *message = [NSString stringWithFormat:@"请选择%@", model.name];
        NSInteger count = 0;
        if (model.model_type == 1) {
            count = 6;
        } else if (model.model_type == 6) {
            for (RBGoodsDetailSpecItemModel *item in model.spec) {
                if (item.selected) {
                    count ++;
                }
            }
        } else {
            if (model.level == 2) {
                for (RBGoodsDetailSpecItemModel *item in model.spec) {
                    if (item.selected) {
                        count ++;
                    }
                }
            } else if (model.level == 3) {
                for (RBGoodsDetailSpecItemModel *gModel in model.spec) {
                    for (RBGoodsDetailSpecItemModel *item in gModel.spec_son) {
                        if (item.selected) {
                            count ++;
                        }
                    }
                }
            }
        }
        if (count == 0) {
            [self.view showTip:message completion:nil];
            return;
        }
    }
    [self showPatientPop];
}
//显示医生信息弹窗
- (void)showPatientPop {
    __weak typeof(self) weak_self = self;
    RBGoodsDetailAttachPopVC *vc = RBGoodsDetailAttachPopVC.new;
    vc.response = self.response.data.user_detail;
    vc.pname = self.pname;
    vc.pgender = self.pgender;
    vc.dnote = self.dnote;
    vc.pics = self.pics;
    vc.completionBlock = ^(NSString * _Nonnull pname, NSString * _Nonnull pgender, NSString * _Nonnull dnote, NSArray * _Nonnull pics) {
        weak_self.pname = pname;
        weak_self.pgender = pgender;
        weak_self.dnote = dnote;
        weak_self.pics = pics;
        [weak_self uploadPatientPics];
    };
    [self presentVc:vc];
}
//处理选择的属性
- (NSString *)handleChooseSpec {
    NSMutableArray *chooseSpecArray = [NSMutableArray array];
    for (RBGoodsDetailSpecModel *model in self.specArray) {
        NSMutableDictionary *dicM = NSMutableDictionary.dictionary;
        dicM[@"id"] = model.id;
        
        NSMutableArray *arrayM = NSMutableArray.array;
        dicM[@"options"] = arrayM;
        
        if (model.model_type == 1) {
            RBGoodsDetailSpecItemModel *item = model.spec[model.selIndex];
            [arrayM addObject:({
                NSMutableDictionary *itemM = NSMutableDictionary.dictionary;
                itemM[@"sid"] = item.id;
                itemM[@"pid"] = @"0";
                itemM[@"num"] = @"0";
                itemM[@"price"] = item.spec_price;
                itemM;
            })];
        } else if (model.model_type == 2 || model.model_type == 4 || model.model_type == 6 || (model.model_type == 3 && model.level == 2)) {
            for (RBGoodsDetailSpecItemModel *item in model.spec) {
                if (item.selected) {
                    [arrayM addObject:({
                        NSMutableDictionary *itemM = NSMutableDictionary.dictionary;
                        itemM[@"sid"] = item.id;
                        itemM[@"pid"] = @"0";
                        
                        NSString *numString = @"0";
                        if (model.model_type == 6) {
                            numString = [NSString stringWithFormat:@"%zd", item.count];
                        }
                        itemM[@"num"] = numString;
                        itemM[@"price"] = item.spec_price;
                        itemM;
                    })];
                }
            }
        } else if (model.model_type == 5 || (model.model_type == 3 && model.level == 3)) {
            for (RBGoodsDetailSpecItemModel *gModel in model.spec) {
                for (RBGoodsDetailSpecItemModel *item in gModel.spec_son) {
                    if (item.selected) {
                        [arrayM addObject:({
                            NSMutableDictionary *itemM = NSMutableDictionary.dictionary;
                            itemM[@"sid"] = item.id;
                            itemM[@"pid"] = item.pid;
                            itemM[@"num"] = @"0";
                            itemM[@"price"] = item.spec_price;
                            itemM;
                        })];
                    }
                }
            }
        }
        
        [chooseSpecArray addObject:dicM];
    }
    
    return chooseSpecArray.jsonStringEncoded;
}

#pragma mark - paramsEvent
/** 1单选模板[显示] */
- (void)paramsType1ItemTapped:(UITapGestureRecognizer *)ges {
    UIView *view = ges.view.superview;
    RBGoodsDetailSpecModel *model = view.rbExData;
    model.selIndex = ges.view.tag - 1000;
    for (UIView *itemView in view.subviews) {
        if (itemView.tag >= 1000) {
            UIImageView *imgView = (UIImageView *)[itemView viewWithTag:333];
            imgView.image = [UIImage imageNamed:model.selIndex == itemView.tag - 1000? @"addressListDefault": @"goodsDetailParamsUnSel"];
        }
    }
}
/** 2多选模板[弹出] */
- (void)paramsType2ViewTapped:(UITapGestureRecognizer *)ges {
    __weak typeof(self) weak_self = self;
    RBGoodsDetailSpecModel *model = ges.view.rbExData;
    RBGoodsDetailMultipleChoosePopVC *vc = RBGoodsDetailMultipleChoosePopVC.new;
    vc.title = model.name;
    vc.options = model.spec;
    vc.dismissBlock = ^{
        for (RBGroupModel *group in weak_self.dataSource) {
            if (group.headerView.tag == 2002) {
                [weak_self reloadParamsType2:group.headerView];
            }
        }
    };
    [self presentVc:vc];
}
/** 2多选模板[弹出] 赋值 */
- (void)reloadParamsType2:(UIView *)view {
    RBGoodsDetailSpecModel *model = view.rbExData;
    UILabel *desL = (UILabel *)[view viewWithTag:333];
    desL.text = ({
        NSMutableArray *arrayM = NSMutableArray.array;
        for (RBGoodsDetailSpecItemModel *item in model.spec) {
            if (item.selected) {
                [arrayM addObject:item.spec_name];
            }
        }
        [arrayM componentsJoinedByString:@" "];
    });
}
/** 3选择器模板[弹出] */
- (void)paramsType3ViewTapped:(UITapGestureRecognizer *)ges {
    __weak typeof(self) weak_self = self;
    RBGoodsDetailSpecModel *model = ges.view.rbExData;
    RBGoodsDetailParamPopVC *vc = RBGoodsDetailParamPopVC.new;
    vc.title = model.name;
    vc.options = model.spec;
    vc.level = model.level;
    vc.dismissBlock = ^{
        for (RBGroupModel *group in weak_self.dataSource) {
            if (group.headerView.tag == 2003) {
                [weak_self reloadParamsType3:group.headerView];
            }
        }
    };
    [self presentVc:vc];
}
/** 3选择器模板[弹出] 赋值 */
- (void)reloadParamsType3: (UIView *)view {
    RBGoodsDetailSpecModel *model = view.rbExData;
    UILabel *desL = (UILabel *)[view viewWithTag:333];
    desL.text = ({
        NSMutableArray *arrayM = NSMutableArray.array;
        if (model.level == 2) {
            for (RBGoodsDetailSpecItemModel *item in model.spec) {
                if (item.selected) {
                    [arrayM addObject:item.spec_name];
                    break;
                }
            }
        } else if(model.level == 3) {
            for (RBGoodsDetailSpecItemModel *gModel in model.spec) {
                for (RBGoodsDetailSpecItemModel *item in gModel.spec_son) {
                    if (item.selected) {
                        [arrayM addObject:gModel.spec_name];
                        [arrayM addObject:item.spec_name];
                        break;
                    }
                }
            }
        }
        [arrayM componentsJoinedByString:@" "];
    });
}
/** 4单选模板[弹出][多项] **/
- (void)paramsType4ViewTapped:(UITapGestureRecognizer *)ges {
    __weak typeof(self) weak_self = self;
    RBGoodsDetailSpecModel *model = ges.view.rbExData;
    RBGoodsDetailMultipleChoosePopVC *vc = RBGoodsDetailMultipleChoosePopVC.new;
    vc.title = model.name;
    vc.options = model.spec;
    vc.singleSelect = YES;
    vc.dismissBlock = ^{
        for (RBGroupModel *group in weak_self.dataSource) {
            if (group.headerView.tag == 2004) {
                [weak_self reloadParamsType4:group.headerView];
            }
        }
    };
    [self presentVc:vc];
}
/** 4单选模板[弹出][多项] 赋值 **/
- (void)reloadParamsType4: (UIView *)view {
    RBGoodsDetailSpecModel *model = view.rbExData;
    UILabel *desL = (UILabel *)[view viewWithTag:333];
    desL.text = ({
        NSMutableArray *arrayM = NSMutableArray.array;
        for (RBGoodsDetailSpecItemModel *item in model.spec) {
            if (item.selected) {
                [arrayM addObject:item.spec_name];
            }
        }
        [arrayM componentsJoinedByString:@" "];
    });
}
/** 6牙排模板[弹出] */
- (void)paramsType6ViewTapped: (UITapGestureRecognizer *)ges {
    __weak typeof(self) weak_self = self;
    RBGoodsDetailSpecModel *model = ges.view.rbExData;
    RBGoodsAddToothPopVC *vc = RBGoodsAddToothPopVC.new;
    vc.title = model.name;
    vc.options = model.spec;
    vc.dismissBlock = ^{
        for (RBGroupModel *group in weak_self.dataSource) {
            if (group.headerView.tag == 2006) {
                [weak_self reloadParamsType6:group.headerView];
            }
        }
    };
    [self presentVc:vc];
}
/** 6牙排模板[弹出] 赋值 */
- (void)reloadParamsType6: (UIView *)view {
    RBGoodsDetailSpecModel *model = view.rbExData;
    UILabel *desL = (UILabel *)[view viewWithTag:333];
    desL.text = ({
        NSMutableArray *arrayM = NSMutableArray.array;
        for (RBGoodsDetailSpecItemModel *item in model.spec) {
            if (item.selected) {
                [arrayM addObject:[NSString stringWithFormat:@"%@(x%zd)",item.spec_name, item.count]];
            }
        }
        [arrayM componentsJoinedByString:@" "];
    });
    [self reloadPrice];
}

#pragma mark - UICollectionViewDataSource & UICollectionViewDelegate

kRBCollectionViewDataSourceAndDelegateAuto(self.dataSource);

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat duration = kRBMainScreenWidth;
    CGFloat factor = MIN(1, scrollView.contentOffset.y/duration);
    self.navigationBar.backgroundAlpha = factor;
    self.titleL.hidden = factor > 0.5? NO: YES;
}

#pragma mark - Setter

#pragma mark - Getter
//导航栏
- (RBNavigationBar *)navigationBar {
    if (!_navigationBar) {
        self.navigationBar = ({
            RBNavigationBar *view = RBNavigationBar.new;
            view.needGradientView = NO;
            [view.naviBar addBackBtn];
            view.bgColor = UIColor.whiteColor;
            
            self.titleL = [RanTool labelWithFontSize:17 weight:0 color:[RBThemeConfig textBlackColor] align:1 text:@"详情"];
            [view.naviBar view_addView:self.titleL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
            self.titleL.hidden = YES;
            
            UIView *backBtn = ({
                UIView *view = UIView.new;
                view.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
                [view rbSetCornerRadius:17];
                
                UIImageView *imgView = [RanTool imgViewWithMode:1 radius:0 imgName:@"backBlack"];
                [view addSubview:imgView];
                [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.center.mas_equalTo(0);
                    make.width.height.mas_equalTo(Zoom(18));
                }];
                
                view;
            });
            [view rbAddTapGesWithTarget:self action:@selector(backBtnTapped)];
            [view setResponseArea:UIEdgeInsetsMake(Zoom(12), Zoom(12), Zoom(12), Zoom(12))];
            [view.naviBar addSubview:backBtn];
            [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(10);
                make.width.height.mas_equalTo(34);
                make.centerY.mas_equalTo(0);
            }];
            
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.mas_equalTo(0);
                make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight);
            }];
            view;
        });
    }
    return _navigationBar;
}
//collectionView
- (UICollectionView *)collectionView {
    if (!_collectionView) {
        self.collectionView = ({
            UICollectionViewFlowLayout *layout = UICollectionViewFlowLayout.new;
            layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize;
            UICollectionView *view = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
            view.showsVerticalScrollIndicator = NO;
            view.showsHorizontalScrollIndicator = NO;
            view.dataSource = self;
            view.delegate = self;
            view.backgroundColor = [RBThemeConfig bgGrayColor];
            kRBIgnoreScrollViewInsetsAdjust(view);
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(0);
                make.right.mas_equalTo(0);
                make.bottom.mas_equalTo(self.bottomView.mas_top);
                make.top.mas_equalTo(kRBStatusBarHeight);
            }];
            view;
        });
    }
    return _collectionView;
}
//数据源
- (NSMutableArray *)dataSource {
    if (!_dataSource) {
        self.dataSource = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            arrayM;
        });
    }
    return _dataSource;
}
//商品信息
- (UIView *)infoViewWith:(RBGoodsDetailModel *)model {
    UIView *view = UIView.new;
    [view view_addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view view_addView:({
            UIView *view = UIView.new;
            [view h_view_addView:({
                UILabel *view = UILabel.new;
                view.tag = 1008611;
                view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                    [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(17)] color:[RBThemeConfig priceRedColor] string:@"¥"];
                    NSArray *priceComponets = [RanTool priceFromPrice:model.price];
                    [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(30)] color:[RBThemeConfig priceRedColor] string:priceComponets[0]];
                    [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(24)] color:[RBThemeConfig priceRedColor] string:[NSString stringWithFormat:@".%@", priceComponets[1]]];
                    [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[UIColor colorWithHexString:@"#8F8F8F"] string:@"　"];
                    [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[UIColor colorWithHexString:@"#8F8F8F"] string:[NSString stringWithFormat:@"￥%@", model.shop_price] lineSpacing:0 througnLineHeight:1 throughLineColor:[UIColor colorWithHexString:@"#8F8F8F"]];
                }];
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            [view h_view_addView:({
                UILabel *view = UILabel.new;
                [view addPriority:1];
                UIFont *font = [UIFont systemFontOfSize:Zoom(12)];
                view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                    [maker addAttributeStringWithImage:[UIImage imageNamed:@"groupShare"] imageSize:CGSizeMake(Zoom(14), Zoom(15)) maxFont:font];
                    [maker addAttributeStringWithFont:font color:[RBThemeConfig textGrayColor] string:@" 分享"];
                }];
                [view rbAddTapGesWithTarget:self action:@selector(shareBtnTapped)];
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(25) bottom:0 left:Zoom(16) right:Zoom(16) centerX:NO];
        
        [view view_addView:({
            UIView *view = UIView.new;
            
            NSMutableArray *tags = NSMutableArray.new;
            if (model.brand_name.length) {
                [tags addObject:model.brand_name];
            }
            for (NSInteger i = 0; i < tags.count; i++) {
                [view h_view_addView:({
                    RBGradientView *view = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#FD7F6E"], [UIColor colorWithHexString:@"#FFC383"]] locations:nil vertical:NO];
                    [view rbSetCornerRadius:Zoom(4)];
                    [view view_addView:({
                        UILabel *view = [RanTool labelWithFontSize:Zoom(12) weight:0 color:UIColor.whiteColor align:0 text:tags[i]];
                        [view addPriority:1];
                        view;
                    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(7) right:Zoom(7) centerX:0];
                    view;
                }) withHeight:Zoom(24) width:CGFLOAT_MIN top:0 bottom:0 left:i? Zoom(10): 0 right:0 centerY:0];
            }
            
            [view h_view_addView:UILabel.new withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            
            [view h_view_addView:({
                UILabel *view = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textGrayColor] align:0 text:[NSString stringWithFormat:@"销量%@", model.sell_number]];
                [view addPriority:2];
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:0 centerY:0];
            
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(22) bottom:0 left:Zoom(16) right:Zoom(16) centerX:0];
        
        [view view_addView:({
            UILabel *view = UILabel.new;
            view.preferredMaxLayoutWidth = kRBMainScreenWidth - Zoom(56);
            view.numberOfLines = 0;
            view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(18)] color:[RBThemeConfig textBlackColor] string:model.good_name lineSpacing:Zoom(7)];
            }];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(18) bottom:Zoom(18) left:Zoom(16) right:Zoom(16) centerX:NO];
        
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(16) bottom:0 left:Zoom(12) right:Zoom(12) centerX:NO];
    view.width = kRBMainScreenWidth;
    
    return view;
}
//属性
/** 1单选模板[显示] */
- (UIView *)paramsSingleDisplayType1ViewWithData:(RBGoodsDetailSpecModel *)data {
    UIView *view = UIView.new;
    [view view_addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view view_addView:({
            UIView *view = UIView.new;
            [view h_view_addView:({
                UILabel *view = [RanTool labelWithFontSize:Zoom(15) weight:2 color:[RBThemeConfig textBlackColor] align:0 text:data.name];
                [view addPriority:1];
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            [view h_view_addView:[RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:@"(必选)"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            view;
        }) withHeight:Zoom(44) width:CGFLOAT_MIN top:Zoom(4) bottom:Zoom(10) left:Zoom(16) right:Zoom(16) centerX:0];
        
        [view view_addView:({
            UIView *view = UIView.new;
            view.rbExData = data;
            for (NSInteger i = 0; i < data.spec.count; i++) {
                RBGoodsDetailSpecItemModel *model = data.spec[i];
                [view h_view_addView:({
                    UIView *view = UIView.new;
                    [view rbAddTapGesWithTarget:self action:@selector(paramsType1ItemTapped:)];
                    view.tag = 1000 + i;
                    [view h_view_addView:({
                        UIImageView *view = [RanTool imgViewWithMode:0 radius:0 imgName:data.selIndex == i? @"addressListDefault": @"goodsDetailParamsUnSel"];
                        view.tag = 333;
                        view;
                    }) withHeight:Zoom(12) width:Zoom(12) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:0 right:0 centerY:YES];
                    [view h_view_addView:[RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:model.spec_name] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(7) right:0 centerY:0];
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:i?Zoom(16):0 right:CGFLOAT_MIN centerY:0];
            }
            view;
        }) withHeight:Zoom(44) width:CGFLOAT_MIN top:0 bottom:Zoom(12) left:Zoom(16) right:Zoom(16) centerX:0];
        
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(12) right:Zoom(12) centerX:NO];
    return view;
}
/** 2多选模板[弹出] */
- (UIView *)paramsMultiplePopType2ViewWithData:(RBGoodsDetailSpecModel *)data {
    UIView *view = UIView.new;
    view.tag = 2002;
    view.rbExData = data;
    [view rbAddTapGesWithTarget:self action:@selector(paramsType2ViewTapped:)];
    [view view_addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:data.name];
            [view addPriority:1];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(21) bottom:Zoom(21) left:Zoom(16) right:0 centerY:0];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textLightBlackColor] align:2 text:@""];
            view.tag = 333;
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:0 centerY:0];
        
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(11) centerY:YES];

        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
    
    [self reloadParamsType2:view];
    return view;
}
/** 3选择器模板[弹出] */
- (UIView *)paramsSelectorPopType3ViewWithData:(RBGoodsDetailSpecModel *)data {
    UIView *view = UIView.new;
    view.tag = 2003;
    view.rbExData = data;
    [view rbAddTapGesWithTarget:self action:@selector(paramsType3ViewTapped:)];
    [view view_addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:data.name];
            [view addPriority:1];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(21) bottom:Zoom(21) left:Zoom(16) right:0 centerY:0];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textLightBlackColor] align:2 text:@""];
            view.tag = 333;
            view.tag = 333;
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:0 centerY:0];
        
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(11) centerY:YES];

        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
    
    return view;
}
/** 4单选模板[弹出][多项] */
- (UIView *)paramsSinglePopType4ViewWithData:(RBGoodsDetailSpecModel *)data {
    UIView *view = UIView.new;
    view.tag = 2004;
    view.rbExData = data;
    [view rbAddTapGesWithTarget:self action:@selector(paramsType4ViewTapped:)];
    [view view_addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:data.name];
            [view addPriority:1];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(21) bottom:Zoom(21) left:Zoom(16) right:0 centerY:0];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textLightBlackColor] align:2 text:@""];
            view.tag = 333;
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:0 centerY:0];
        
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(11) centerY:YES];

        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
    
    return view;
}
/** 5牙位模板[显示]; */
- (UIView *)paramsChooseToothDisplayType5ViewWithData:(RBGoodsDetailSpecModel *)data {
    UIView *view = UIView.new;
    view.rbExData = data;
    [view view_addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        //牙齿选择
        [view view_addView:({
            UIView *view = UIView.new;
            [view h_view_addView:({
                UILabel *view = [RanTool labelWithFontSize:Zoom(15) weight:2 color:[RBThemeConfig textBlackColor] align:0 text:@"牙齿选择"];
                [view addPriority:1];
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            [view h_view_addView:[RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:data.is_add_type == 0? @"(固定价格)": @"(商品价格)"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
            view;
        }) withHeight:Zoom(44) width:CGFLOAT_MIN top:0 bottom:Zoom(10) left:Zoom(16) right:Zoom(16) centerX:0];
        //牙齿
        NSArray *toothArray = [self toothArrayWithModel:data];
        for (NSDictionary *dic in toothArray) {
            [view view_addView:[self toothViewWithData:dic] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(16) bottom:Zoom(26) left:0 right:0 centerX:0];
        }
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(12) right:Zoom(12) centerX:NO];
    return view;
}
- (NSArray *)toothArrayWithModel: (RBGoodsDetailSpecModel *)model {
    NSMutableArray *arrayM = NSMutableArray.array;
    for (NSInteger i = 0; i < 4; i++) {
        NSMutableDictionary *dic = NSMutableDictionary.dictionary;
        dic[@"title"] = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            for (RBGoodsDetailSpecItemModel *item in model.spec) {
                [arrayM addObject:item.spec_name];
            }
            arrayM;
        })[i];
        dic[@"img"] = @[@"tup",@"tup",@"tdown",@"tdown"][i];
        dic[@"imgSel"] = @[@"tupSel",@"tupSel",@"tdownSel",@"tdownSel"][i];
        dic[@"count"] = @"8";
        dic[@"data"] = model.spec[i];
        [arrayM addObject:dic];
    }
    return arrayM;
}
- (NSMutableArray *)toothBtnsArrayM {
    if (!_toothBtnsArrayM) {
        self.toothBtnsArrayM = NSMutableArray.array;
    }
    return _toothBtnsArrayM;
}
- (UIView *)toothViewWithData: (NSDictionary *)dic {
    UIView *view = UIView.new;
    [view view_addView:[RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textGrayColor] align:0 text:dic[@"title"]] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(13) right:0 centerX:0];
    RBGoodsDetailSpecItemModel *model = dic[@"data"];
    [view view_addView:({
        UIView *view = UIView.new;
        NSInteger count = [dic[@"count"] integerValue];
        for (NSInteger i = 1; i <= count; i++) {
            UIButton *btn = UIButton.new;
            btn.rbExData = model.spec_son[i-1];
            if ([dic[@"img"] containsString:@"tup"]) {
                btn.titleEdgeInsets = UIEdgeInsetsMake(Zoom(10), 0, 0, 0);
            } else {
                btn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, Zoom(5), 0);
            }
            [btn setBackgroundImage:[UIImage imageNamed:dic[@"img"]] forState:UIControlStateNormal];
            [btn setBackgroundImage:[UIImage imageNamed:dic[@"imgSel"]] forState:UIControlStateSelected];
            [btn rbSetTitleColor:UIColor.whiteColor];
            [btn rbSetFontSize:Zoom(13)];
            [btn rbSetTitle:[NSString stringWithFormat:@"%zd", i]];
            [btn rbAddTarget:self action:@selector(toothBtnTapped:)];
            [self.toothBtnsArrayM addObject:btn];
            [view h_view_addView:btn withHeight:CGFLOAT_MIN width:Zoom(24) top:0 bottom:0 left:i == 1? 0: Zoom(18) right:CGFLOAT_MIN centerY:0];
        }
        view;
    }) withHeight:Zoom(27) width:CGFLOAT_MIN top:Zoom(13) bottom:0 left:Zoom(13) right:0 centerX:0];
    return view;
}
/** 6牙排模板[弹出] */
- (UIView *)paramsAddToothPopType6ViewWithData:(RBGoodsDetailSpecModel *)data {
    UIView *view = UIView.new;
    view.tag = 2006;
    view.rbExData = data;
    [view rbAddTapGesWithTarget:self action:@selector(paramsType6ViewTapped:)];
    [view view_addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:data.name];
            [view addPriority:1];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(21) bottom:Zoom(21) left:Zoom(16) right:0 centerY:0];
        
        [view h_view_addView:({
            UILabel *view = [RanTool labelWithFontSize:Zoom(11) weight:0 color:[RBThemeConfig textLightBlackColor] align:2 text:@""];
            view.tag = 333;
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:0 centerY:0];
        
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(11) centerY:YES];

        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
    
    return view;
}
//添加一个占位
- (RBGroupModel *)paddingGroupWithHeight: (CGFloat)height {
    RBGroupModel *group = RBGroupModel.new;
    group.headerReuseIdentifier = NSStringFromClass(RBCollectionReusableView.class);
    group.headerView = UIView.new;
    group.headerReferenceSize = CGSizeMake(kRBMainScreenWidth, height);
    return group;
}
//店铺信息
- (UIView *)shopViewWith:(RBGoodsDetailModel *)data {
    UIView *view = UIView.new;
    view.backgroundColor = UIColor.whiteColor;
    [view rbSetCornerRadius:Zoom(8)];
    
    [view view_addView:({
        UIView *view = UIView.new;
        [view h_view_addView:[RanTool imgViewWithMode:2 radius:Zoom(22) imgName:data.shop_info.logo] withHeight:Zoom(44) width:Zoom(44) top:0 bottom:0 left:0 right:0 centerY:0];
        [view h_view_addView:({
            UIView *view = UIView.new;
            [view view_addView:[RanTool labelWithFontSize:Zoom(15) weight:2 color:[RBThemeConfig textBlackColor] align:0 text:data.shop_info.store_name] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
            [view view_addView:[RanTool labelWithFontSize:Zoom(12) weight:1 color:[RBThemeConfig textGrayColor] align:0 text:data.shop_info.content] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(7) bottom:0 left:0 right:0 centerX:0];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(11) right:0 centerY:YES];
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:0 centerY:YES];
       
        [view rbAddTapGesWithTarget:self action:@selector(tapShopInfo:)];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(17) bottom:0 left:Zoom(10) right:Zoom(10) centerX:NO];
    
    [view view_addView:({
        UIScrollView *view = UIScrollView.new;
        view.showsVerticalScrollIndicator = NO;
        view.showsHorizontalScrollIndicator = NO;
        [view h_rbSetContentHeight:Zoom(100)];
        for (RBGoodsDetailShopGoodsModel *model in data.shop_info.shop_goods) {
            [view h_addView:({
                UIView *view = UIView.new;
                [view view_addView:[RanTool imgViewWithMode:2 radius:Zoom(8) imgName:model.picurl] withHeight:Zoom(78) width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
                [view view_addView:UILabel.new withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
                [view view_addView:({
                    UILabel *view = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textBlackColor] align:1 text:model.good_name];
                    [view addVPriority:1];
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
                view.rbExData = model;
                [view rbAddTapGesWithTarget:self action:@selector(tapShopGood:)];
                view;
            }) withHeight:CGFLOAT_MIN width:Zoom(78) top:0 bottom:0 left:Zoom(8) right:Zoom(8) centerY:0];
        }
        view;
    }) withHeight:Zoom(100) width:CGFLOAT_MIN top:Zoom(15) bottom:0 left:0 right:0 centerX:0];
    
    [view view_addView:({
//        UIView *view = UIView.new;
//        [view h_view_addView:({
//            UIView *view = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textBlackColor] align:1 text:@"联系客服" bgColor:nil radius:Zoom(15) borderWidth:1 borderColor:@"#BFBFBF" lines:1 linePadding:0 hPriority:0];
//            [view rbAddTapGesWithTarget:self action:@selector(clickContactService)];
//            view;
//        }) withHeight:CGFLOAT_MIN width:Zoom(100) top:0 bottom:0 left:Zoom(66) right:0 centerY:0];
//        [view h_view_addView:({
            UIView *view = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textBlackColor] align:1 text:@"进店逛逛" bgColor:nil radius:Zoom(15) borderWidth:1 borderColor:@"#BFBFBF" lines:1 linePadding:0 hPriority:0];
            [view rbAddTapGesWithTarget:self action:@selector(tapShop:)];
//            view;
//        }) withHeight:CGFLOAT_MIN width:Zoom(100) top:0 bottom:0 left:Zoom(14) right:CGFLOAT_MIN centerY:0];
        view;
    }) withHeight:Zoom(30) width:Zoom(100) top:Zoom(29) bottom:Zoom(20) left:0 right:0 centerX:1];
    
    return view;
}
//为你推荐
- (UIView *)recViewWith:(RBGoodsDetailModel *)data {
    UIView *view = UIView.new;
    view.backgroundColor = UIColor.whiteColor;
    [view rbSetCornerRadius:Zoom(8)];
    
    [view view_addView:({
        UIView *view = UIView.new;
        [view h_view_addView:[RanTool labelWithFontSize:Zoom(15) weight:2 color:[RBThemeConfig textBlackColor] align:0 text:@"为你推荐"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:0 centerY:YES];
        view;
    }) withHeight:Zoom(50) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(11) right:Zoom(11) centerX:0];
        
    [view view_addView:({
        UIView *view = UIView.new;
        CGFloat itemW = Zoom(109);
        CGFloat itemH = Zoom(160);
        
        for (RBGoodsDetailShopGoodsModel *model in data.cate_goods) {
            NSInteger index = [data.cate_goods indexOfObject:model];
    
            NSInteger column = index % 3;
            [view view_addView:({
                UIView *view = UIView.new;
                [view view_addView:[RanTool imgViewWithMode:2 radius:Zoom(4) imgName:model.picurl] withHeight:itemW width:itemW top:0 bottom:0 left:0 right:0 centerX:0];
                [view view_addView:[RanTool labelWithFontSize:Zoom(13) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:model.good_name bgColor:nil radius:0 borderWidth:0 borderColor:nil lines:2 linePadding:Zoom(3) hPriority:0] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(8) bottom:0 left:0 right:0 centerX:0];
                [view view_addView:[RanTool labelWithFontSize:Zoom(13) weight:2 color:[RBThemeConfig priceRedColor] align:0 text:[NSString stringWithFormat:@"¥%@",model.sell_price]] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:CGFLOAT_MIN left:0 right:0 centerX:0];
                view.rbExData = model;
                [view rbAddTapGesWithTarget:self action:@selector(tapShopGood:)];
                view;
            }) withHeight:itemH width:itemW top:column == 0? 0: -itemH bottom:CGFLOAT_MIN left:column*(itemW + Zoom(5)) right:CGFLOAT_MIN centerX:NO];
        }
        
        [view view_addView:UIView.new withHeight:1 width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:Zoom(17) left:Zoom(8) right:0 centerX:0];
    
    return view;
}
//详情
- (UIView *)detailView {
    UIView *view = UIView.new;
    view.backgroundColor = UIColor.whiteColor;
    [view rbSetCorner:UIRectCornerTopLeft | UIRectCornerTopRight radius:Zoom(8)];
    
    [view view_addView:({
        UIView *view = UIView.new;
        [view h_view_addView:[RanTool labelWithFontSize:Zoom(15) weight:2 color:[RBThemeConfig textBlackColor] align:0 text:@"详情"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(13) width:Zoom(8) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:0 centerY:YES];
        view;
    }) withHeight:Zoom(50) width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(11) right:Zoom(11) centerX:0];

    return view;
}
//
- (UIView *)goodsDetailView {
    if (!_goodsDetailView) {
        self.goodsDetailView = ({
            UIView *view = UIView.new;
            
            UIView *innerView = UIView.new;
            innerView.backgroundColor = UIColor.whiteColor;
            [view addSubview:innerView];
            [innerView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(0);
                make.left.mas_equalTo(Zoom(12));
                make.right.mas_equalTo(-Zoom(12));
            }];
            
            [innerView addSubview:self.detailWebView];
            [self.detailWebView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.bottom.mas_equalTo(0);
                make.left.mas_equalTo(Zoom(10));
                make.right.mas_equalTo(-Zoom(10));
            }];
            
            
            view;
        });
    }
    return _goodsDetailView;
}
//webView
- (RBGoodsDetailWebView *)detailWebView {
    if (!_detailWebView) {
        self.detailWebView = ({
            RBGoodsDetailWebView *view = [RBGoodsDetailWebView.alloc initWithFrame:CGRectMake(0, 0, kRBMainScreenWidth - Zoom(12)*2 - Zoom(10)*2, 10)];
            view;
        });
    }
    return _detailWebView;
}
//底部view
- (UIView *)bottomView {
    if (!_bottomView) {
        self.bottomView = ({
            UIView *view = UIView.new;
            view.backgroundColor = UIColor.whiteColor;
            view.layer.shadowColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1].CGColor;
            view.layer.shadowOffset = CGSizeMake(0,0);
            view.layer.shadowOpacity = 1;
            view.layer.shadowRadius = 5;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_equalTo(0);
                make.height.mas_equalTo(Zoom(59));
                make.bottom.mas_equalTo(-kRBSafeBottomHeight);
            }];
            
            CGFloat itemW = Zoom(42);
            
            [view h_view_addView:({
                UIView *view = UIView.new;
                [view view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"orderDetailShop"] withHeight:Zoom(17) width:Zoom(17) top:Zoom(15) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
                [view view_addView:[RanTool labelWithFontSize:Zoom(10) weight:0 color:@"#454545" align:1 text:@"店铺"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(5) bottom:CGFLOAT_MIN left:0 right:0 centerX:0];
                [view rbAddTapGesWithTarget:self action:@selector(tapShop:)];
                view;
            }) withHeight:CGFLOAT_MIN width:itemW top:0 bottom:0 left:Zoom(8) right:0 centerY:0];
            
            [view h_view_addView:({
                UIView *view = UIView.new;
                [view view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"orderDetailService"] withHeight:Zoom(17) width:Zoom(17) top:Zoom(15) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
                [view view_addView:[RanTool labelWithFontSize:Zoom(10) weight:0 color:@"#454545" align:1 text:@"客服"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(5) bottom:CGFLOAT_MIN left:0 right:0 centerX:0];
                [view rbAddTapGesWithTarget:self action:@selector(clickContactService)];
                view;
            }) withHeight:CGFLOAT_MIN width:itemW top:0 bottom:0 left:0 right:0 centerY:0];
            
            [view h_view_addView:({
                UIView *view = UIView.new;
                [view view_addView:({
                    UIImageView *imgV = [RanTool imgViewWithMode:1 radius:0 imgName:@"orderDetailCollect"];
                    imgV.tag = 1001011;
                    imgV;
                }) withHeight:Zoom(17) width:Zoom(17) top:Zoom(15) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
                [view view_addView:({
                    UILabel *view = [RanTool labelWithFontSize:Zoom(10) weight:0 color:@"#454545" align:1 text:@"收藏"];
                    view.tag = 1001012;
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(5) bottom:CGFLOAT_MIN left:0 right:0 centerX:0];
                [view rbAddTapGesWithTarget:self action:@selector(collectTap)];
                view;
            }) withHeight:CGFLOAT_MIN width:itemW top:0 bottom:0 left:0 right:0 centerY:0];
          
            CGFloat btnW = Zoom(106);
            CGFloat btnH = Zoom(40);
            
            [view h_view_addView:({
                RBGradientView *view = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#F87628"], [UIColor colorWithHexString:@"#F23030"]] locations:nil vertical:NO];
                [view rbAddTapGesWithTarget:self action:@selector(addCartBtnTapped)];
                [view rbSetCornerRadius:btnH/2];
                [view view_addView:[RanTool labelWithFontSize:Zoom(14) weight:0 color:UIColor.whiteColor align:1 text:@"加入购物车"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
                view;
            }) withHeight:btnH width:btnW top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(8) right:CGFLOAT_MIN centerY:YES];
            
            [view h_view_addView:({
                RBGradientView *view = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#518CFF"], [UIColor colorWithHexString:@"#2A6DF0"]] locations:nil vertical:NO];
                [view rbAddTapGesWithTarget:self action:@selector(buyBtnTapped)];
                [view rbSetCornerRadius:btnH/2];
                [view view_addView:[RanTool labelWithFontSize:Zoom(14) weight:0 color:UIColor.whiteColor align:1 text:@"立即购买"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
                view;
            }) withHeight:btnH width:btnW top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(5) right:CGFLOAT_MIN centerY:YES];
            
            view;
        });
    }
    return _bottomView;
}
//上传图片的工具
- (RBUploadTool *)uploadTool {
    if (!_uploadTool) {
        self.uploadTool = RBUploadTool.new;
    }
    return _uploadTool;
}

@end
